<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('审核销售订单')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-audit">
            <input name="orderId" th:value="${salesOrder.orderId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">订单编号：</label>
                <div class="col-sm-8">
                    <input name="orderCode" th:value="${salesOrder.orderCode}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">客户公司：</label>
                <div class="col-sm-8">
                    <input name="customerName" th:value="${salesOrder.customerName}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">商品名称：</label>
                <div class="col-sm-8">
                    <input name="productName" th:value="${salesOrder.productName}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">商品类别：</label>
                <div class="col-sm-8">
                    <input name="categoryId" th:value="${@dict.getLabel('product_category', salesOrder.categoryId)}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">订单金额：</label>
                <div class="col-sm-8">
                    <input name="totalAmount" th:value="${salesOrder.totalAmount}" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group" th:if="${salesOrder.auditStatus != '0'}">    
                <label class="col-sm-3 control-label">当前审核状态：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" th:value="${salesOrder.auditStatus == '1' ? '审核通过' : '审核不通过'}" readonly>
                </div>
            </div>
            <div class="form-group" th:if="${salesOrder.auditStatus != '0'}">    
                <label class="col-sm-3 control-label">原审核意见：</label>
                <div class="col-sm-8">
                    <textarea class="form-control" readonly th:text="${salesOrder.auditOpinion}"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">审核结果：</label>
                <div class="col-sm-8">
                    <label class="radio-box"> <input type="radio" name="result" value="1" th:checked="${salesOrder.auditStatus == '1' || salesOrder.auditStatus == '0'}"> 通过 </label>
                    <label class="radio-box"> <input type="radio" name="result" value="2" th:checked="${salesOrder.auditStatus == '2'}"> 拒绝 </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">审核意见：</label>
                <div class="col-sm-8">
                    <textarea name="auditOpinion" class="form-control" required></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "sales/audit";
        
        $("#form-audit").validate({
            focusCleanup: true
        });
        
        function submitHandler() {
            if ($.validate.form()) {
                var data = $('#form-audit').serializeArray();
                var orderId = $("input[name='orderId']").val();
                var auditOpinion = $("textarea[name='auditOpinion']").val();
                var result = $("input[name='result']:checked").val();
                
                if (result === "1") {
                    // 审核通过
                    $.operate.post(prefix + "/approve", { "orderId": orderId, "auditOpinion": auditOpinion }, function(result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.close();
                            $.modal.msgSuccess("操作成功");
                            $.table.refresh();
                        } else {
                            $.modal.alertError(result.msg);
                        }
                    });
                } else {
                    // 审核拒绝
                    $.operate.post(prefix + "/reject", { "orderId": orderId, "auditOpinion": auditOpinion }, function(result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.close();
                            $.modal.msgSuccess("操作成功");
                            $.table.refresh();
                        } else {
                            $.modal.alertError(result.msg);
                        }
                    });
                }
            }
        }
    </script>
</body>
</html> 